package com.tg.app.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.tg.app.R;
import com.tg.app.util.LogUtils;
import com.tg.appcommon.android.TGLog;

public class CameraPlayerPlayBackControlView extends LinearLayout {
    private static final String TAG = "CameraPlayerPlayBackControlView";
    private ImageButton pauseBtn, resumeBtn;

    private OnControlClickListener listener;

    public void setClickListener(OnControlClickListener listener) {
        this.listener = listener;
    }

    public CameraPlayerPlayBackControlView(Context context) {
        super(context);
        init(context);
    }

    public CameraPlayerPlayBackControlView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CameraPlayerPlayBackControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_camera_player_playback_control_view, this);
        pauseBtn = view.findViewById(R.id.ib_camera_player_playback_control_play_pause);
        resumeBtn = view.findViewById(R.id.ib_camera_player_playback_control_play_resume);
        pauseBtn.setOnClickListener(v -> {
            if (listener!=null){
                listener.onControl(true);
            }
        });
        resumeBtn.setOnClickListener(v -> {
            if (listener!=null){
                listener.onControl(false);
            }
        });
    }
    public void showPause(){
        setVisibility(VISIBLE);
        TGLog.d(TAG, "showPlaybackControl showPause");
        pauseBtn.setVisibility(VISIBLE);
        resumeBtn.setVisibility(GONE);
    }
    public void showResume(){
        TGLog.d(TAG, "showPlaybackControl showResume");
        setVisibility(VISIBLE);
        pauseBtn.setVisibility(GONE);
        resumeBtn.setVisibility(VISIBLE);
    }
    public  interface OnControlClickListener {
        void onControl(boolean pause);
    }
}
